package com.gitee.huxing.course;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.time.LocalDateTime;
import java.util.Scanner;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course
 * @ClassName: SpringbootJavaCourseApplication
 * @Author: huxing
 * @DateTime: 2021-09-05 上午8:50
 */
@Slf4j
@SpringBootApplication
public class JavaCourseApplication implements CommandLineRunner {

    /** 自定义数据源连接 **/
    private final static String JDBC_CUSTOM = "custom";

    /** hikari数据连接池 **/
    private final static String JDBC_HIRKARI = "hikari";

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(JavaCourseApplication.class);
        Scanner scan = new Scanner(System.in);
        System.out.println("**** jdbc 启动加载模式 *****");
        System.out.println(" 1: 自定义jdbc源数据源加载");
        System.out.println(" 2: 采用hirkari数据库连接池加载");
        System.out.println("****************************");
        System.out.print("请选择加载模式: ");
        int loadModule = scan.nextInt();
        if (loadModule == 1){
            // 普通单例测试
            application.setAdditionalProfiles(JDBC_CUSTOM);
        } else if (loadModule == 2){
            // 并发压力测试
            application.setAdditionalProfiles(JDBC_HIRKARI);
        }
        application.run(args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("系统服务启动: {}", LocalDateTime.now());
    }
}
